package com.koron.css2.newProjectCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.mapper.PubReceiptMapper;
import com.koron.css2.newProjectCenter.bean.query.PjTimePostponeQueryBean;
import com.koron.css2.newProjectCenter.mapper.PjProcessNodeTimePostponeMapper;
import com.koron.css2.newProjectCenter.service.PjInfoService;
import com.koron.css2.newProjectCenter.vo.PjProcessNodeTimePostponeListVO;
import com.koron.css2.serviceManage.bean.ProcessNodeBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.DBSourceUtils;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户工程延期详情查询
 * @author admin
 * @version 2.1
 * @since 2021-06-08
 *
 */
public class PjTimePostponeQuery implements ServerInterface{

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			PjTimePostponeQueryBean queryBean = JsonUtils.objectToPojo(req.getData(), PjTimePostponeQueryBean.class);
			if(StringUtils.isEmpty(queryBean.getId())) {
				return MessageBean.create(Constant.MESSAGE_INT_FAIL, "id 不能为空", Void.class);
			}
			PjProcessNodeTimePostponeMapper mapper = factory.getMapper(PjProcessNodeTimePostponeMapper.class);
			PjProcessNodeTimePostponeListVO pjTimePostpone = mapper.selectDetailsById(queryBean.getId());
			Map<String, String> param = new HashMap<String, String>();
			param.put("receiptType", PjInfoService.PROJECT_INFO_NEW_RECEIPT);
			param.put("nodeCode", pjTimePostpone.getNodeCode());
			PubReceiptMapper pubReceiptMapper = factory.getMapper(PubReceiptMapper.class, DBSourceUtils.getDbEnv(userInfo.getCurWaterCode() + ""));
			List<ProcessNodeBean> list = pubReceiptMapper.listProcessNodeByBillType(param);
			pjTimePostpone.setNodeName(list.get(0).getNodeName());
			MessageBean<PjProcessNodeTimePostponeListVO> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", PjProcessNodeTimePostponeListVO.class);
			info.setData(pjTimePostpone);
			return info;
		}catch(Exception e){
			logger.error("工程延期详情查询失败"+e.getMessage(), e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "工程延期详情查询失败", null);
		}
	}
}
